/*
 * @Description  : 表格
 * @Author       : zhao
 * @Date         : 2022-07-13 08:56:00
 * @LastEditors  : zhao
 * @LastEditTime : 2023-02-02 17:10:12
 */
import { defineStore } from 'pinia';

import { TableListStates } from './interface';
import { useUserInfo } from './userInfo.ts';
import { useBorrow } from './borrow.ts';
import { useUpdataMaintain } from './updataMaintain';
import { useSignalr } from './signalr';
import { usePublicity } from './publicity.ts';
import { toRaw } from '@vue/reactivity'
/**
 * 表格信息
 * @methods setUserInfos 设置表格信息
 */

const modelName: any = {
	useUserInfo: useUserInfo,
	useBorrow: useBorrow,
	useUpdataMaintain: useUpdataMaintain,
	usePublicity: usePublicity,
}
export const useTableInfo = defineStore('zTable', {
	state: (): TableListStates => ({
		zTable: {
			tableHeader: [],
			tableData: [],
			menuData: [],
			rowData: {},
			selectRows: [],
			routerUrl: "",
			mdName: {
				name: '',
				url: ''
			},//获取相应模块
		},
		zTableType: {
			border: false,
			selection: true,
			index: true,
			menu: false
		},
		zpagination: {
			currentPage: 1,
			pageSize: 10,
			total: 10
		},
		searchType: [],
		searchData: {
			pageSize: 10,
			pageIndex: 1,
		},
		zTableFunction: {
			add: false,
			modify: false,
			upload: false,
			delete: false,
		},//表格功能列 功能显隐
		zTableFunAddShow: false,//新增页面开关
		zTableFunEditShow: false,//修改页面开关
		zTableFunDelShow: false,//删除页面开关
		menuType: {
			activeIndex: "menu0"
		},
		buttonLoading: false
	}),
	actions: {
		async getTableData() {

			if (this.zTable.mdName.url == "CSGetBorrowingForm") useSignalr().eliminateUnreadNum()

			const tbData = modelName[this.zTable.mdName.name]()

			const { data, code, count } = await tbData[this.zTable.mdName.url](this.searchData)

			if (code == 200) this.zTable.tableData = data

			this.zpagination.total = count
		},


	},
	persist: <any>{
		// // 修改存储中使用的键名称，默认为当前 Store的 id
		// key: 'rowData',
		// // 修改为 sessionStorage，默认为 localStorage
		// storage: window.sessionStorage,
		// // 部分持久化状态的点符号路径数组，[]意味着没有状态被持久化(默认为undefined，持久化整个状态)
		// paths: ['zTable.rowData', 'zTable.selectRows'],
		enabled: true,
		strategies: [
			{ storage: window.sessionStorage, key: 'rowData', paths: ['zTable.rowData'] },
			{ storage: window.sessionStorage, key: 'selectRows', paths: ['zTable.selectRows'] },
			{ storage: window.sessionStorage, key: 'menuType', paths: ['menuType'] },
		],
	},
});
